package com.infore.authorityManagement.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.authorityManagement.entity.BusinessConstant;
import com.infore.authorityManagement.entity.UserLoginInfo;
import com.infore.authorityManagement.enums.ResultStatus;
import com.infore.authorityManagement.service.IUserLoginInfoService;
import com.infore.authorityManagement.util.Page;
import com.infore.authorityManagement.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "用户登陆信息管理", tags = "用户登陆信息管理")
@RequestMapping(value = "/userLoginInfo")
@RestController
public class UserLoginInfoController {
    
    @Autowired
    IUserLoginInfoService loginInfoService;
    
    @ApiOperation(value = "查询用户登陆信息", notes = "批量获取用户登陆信息，约定：当pageSize小于1 或者 pageNo小于0或者其中一个为空时，不进行分页操作")
    @ApiImplicitParams({ @ApiImplicitParam(name = "loginInfo", value = "登陆信息", required = false, dataType = "UserLoginInfo"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageNo", value = "第几页", required = false, dataType = "Integer") })
    @RequestMapping(value = "", method = RequestMethod.GET)
    public @ResponseBody ResultEntity getUsers(UserLoginInfo loginInfo, Integer pageSize, Integer pageNo, String token) {
        if (pageSize == null || pageNo == null || pageSize < 1 || pageNo < 0) {
            List<UserLoginInfo> list = loginInfoService.getLoginInfo(loginInfo);
            return new ResultEntity(ResultStatus.SUCCESS, BusinessConstant.QUERY_SUCCESS).setDataList(list);
        } else {
            Page<UserLoginInfo> page = loginInfoService.getLoginInfoForPage(loginInfo, pageSize, pageNo);
            return new ResultEntity(ResultStatus.SUCCESS, BusinessConstant.QUERY_SUCCESS).setPage(page);
        }

    }

}
